# 搜索文件 选中规定大小的图片，修改图片名称


import os,zipfile
import re
import sys
path = r"C:\Users\wangj\Desktop\tmp"
fileList = os.listdir(path)  # 待修改文件夹
# print("修改前：" + str(fileList))  # 输出文件夹中包含的文件
os.chdir(path)  # 将当前工作目录修改为待修改文件夹的位置
num = 1  # 名称变量
# f = zipfile.ZipFile('东滩右.rar', 'w', zipfile.ZIP_DEFLATED)
class_1_num = 0
class_0_num = 0
for fileName in fileList: 
    print(fileName)
    if fileName.split('.')[-1] not in ['jpg']:
        continue
    # f.write(fileName)
    img_size = os.path.getsize(os.path.join(path,fileName))
    if img_size < 1024 * 200:
        # 图片大小 小于200Kb 删除
        os.remove(os.path.join(path,fileName))
        continue
    class_name = int(fileName.split('_')[1])
    if class_name == 1:
        class_1_num = class_1_num + 1
    else:
        class_0_num = class_0_num + 1
    # print(fileName.split('_'))
    # print('c' + str(class_name) +'_'+fileName.split('_')[2]+'_'+fileName.split('_')[3])
    os.rename(fileName, ('c' + str(class_name) +'_'+fileName.split('_')[2]+'_'+fileName.split('_')[3]))  # 文件重新命名
    print('{}/{}'.format(num,len(fileList)))
    num = num + 1
# f.close()
print("---------------------------------------------------")
print('0  1  = {}\t{}'.format(class_0_num,class_1_num))
sys.stdin.flush()  # 刷新